home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / strsed.zoo / check2.c < prev    next >
C/C++ Source or Header  |  1992-07-06  |  958b  |  52 lines

  1. #include <stdio.h>
  2.  
  3. int
  4. main()
  5. {
  6.     /*
  7.      * Check simple searching.
  8.      *
  9.      * Input consists of sets of four lines containing
  10.      *
  11.      *      text
  12.      *      pattern
  13.      *      expected start of match
  14.      *      expected end of match
  15.      *
  16.      * See the file examples2
  17.      *
  18.      */
  19.  
  20.     extern int atoi();
  21.     extern char *strsed();
  22.  
  23.     char text[1024];
  24.     char pat[1024];
  25.     char ans1[10];
  26.     char ans2[10];
  27.     int range[2];
  28.     int low;
  29.     int high;
  30.     register int testno = 0;
  31.     int error = 0;
  32.  
  33.     while (gets(text) && gets(pat) && gets(ans1) && gets(ans2)){
  34.         testno++;
  35.         strsed(text, pat, range);
  36.         low = atoi(ans1);
  37.         high = atoi(ans2);
  38.         if (low != range[0] || high != range[1]){
  39.             error = 1;
  40.             printf("WARNING (test %d)... strsed(%s, %s) returns range %d-%d (Expected %d-%d)\n", 
  41.                 testno, text, pat, range[0], range[1], low, high);
  42.             fflush(stdout);
  43.         }
  44.     }
  45.  
  46.     if (!error){
  47.         printf("Searching tests passed successfully.\n");
  48.     }
  49.  
  50.     return 0;
  51. }
  52.